<?php

use backend\models\c2\form\EavForm;
use kzo\base\widgets\ui\bs4\Alert;
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use yii\widgets\Pjax;

/** @var $model EavForm */

$messageName = $model->getMessageName();
$attributes = $model->getEavFormAttributes();
?>

<?php Pjax::begin(['id' => $model->getPjaxName(), 'formSelector' => $model->getBaseFormName(true), 'enablePushState' => false]) ?>

<?php
$form = ActiveForm::begin([
            'action' => ['eav-save'],
            'options' => [
                'id' => $model->getBaseFormName(),
                'data-pjax' => true,
            ],
            'fieldConfig' => [
                'template' => "{label}\n{hint}\n{input}\n{error}",
            ],
        ]);
?>

<div class="<?= $model->getPrefixName('form') ?>">

    <?php if (Yii::$app->session->hasFlash($messageName)): ?>
        <?php if (!$model->hasErrors()) {
            echo Alert::widget([
                'type' => Alert::TYPE_SUCCESS,
                'title' => 'Well Down',
                'icon' => 'fas fa-ok-circle',
                'body' => Yii::$app->session->getFlash($messageName),
                'showSeparator' => true,
                'delay' => 2000
            ]);
        } else {
            echo Alert::widget([
                'type' => Alert::TYPE_WARNING,
                'title' => 'Warning!',
                'icon' => 'fas fa-ok-circle',
                'body' => Yii::$app->session->getFlash($messageName),
                'showSeparator' => true,
            ]);
        }
        ?>
    <?php endif; ?>

    <div class="well">
        <?php
        if (count($attributes) > 0) {
            echo Form::widget([
                'model' => $model,
                'form' => $form,
                'columns' => 4,
                'attributes' => $attributes
            ]);
            echo Html::hiddenInput('entity_id', $model->entityModel->id);

            echo Html::beginTag('div', ['class' => 'box-footer']);
            echo Html::submitButton('<i class="fa fa-save"></i> ' . Yii::t('app.c2', 'Save'), ['type' => 'button', 'class' => 'btn btn-primary pull-right']);
            echo Html::a('<i class="fa fa-arrow-left"></i> ' . Yii::t('app.c2', 'Go Back'), ['index'], ['class' => 'btn btn-default pull-right', 'title' => Yii::t('app.c2', 'Go Back'),]);
            echo Html::endTag('div');
        } else {
            echo Yii::t('app.c2', 'There are not available attributes for now!');
        }
        ?>
    </div>
</div>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
